package gold.digger;

import gold.utils.InputUtil;

import java.util.*;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC2034 {
    public long startExecuteTime = System.currentTimeMillis();


    class StockPrice {
        int cur;
        Map<Integer, Integer> map = new HashMap<>();
        TreeMap<Integer, Integer> ts = new TreeMap<>();

        public void update(int timestamp, int price) {
            cur = Math.max(cur, timestamp);
            if (map.containsKey(timestamp)) {
                int old = map.get(timestamp);
                int cnt = ts.get(old);
                if (cnt == 1) ts.remove(old);
                else ts.put(old, cnt - 1);
            }
            map.put(timestamp, price);
            ts.put(price, ts.getOrDefault(price, 0) + 1);
        }

        public int current() {
            return map.get(cur);
        }

        public int maximum() {
            return ts.lastKey();
        }

        public int minimum() {
            return ts.firstKey();
        }
    }

    public void run() {
        StockPrice solution = new StockPrice();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC2034 an = new LC2034();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
